home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_13_05 / allison / date.c < prev    next >
C/C++ Source or Header  |  1995-03-12  |  696b  |  29 lines

  1. LISTING 2 - Implementation for the Date type
  2. /* date.c */
  3.  
  4. #include <stdio.h>
  5. #include "date.h"
  6.  
  7. static const char *month_text[] =
  8.     {"Bad month", "January", "February", "March", "April",
  9.     "May", "June", "July", "August", "September", "October",
  10.     "November", "December"};
  11.  
  12. char *date_format(const Date *dp, char *buf)
  13. {
  14.     sprintf(buf,"%s %d, %d", 
  15.             month_text[dp->month],dp->day,dp->year);
  16.     return buf;
  17. }
  18.  
  19. int date_compare(const Date *dp1, const Date *dp2)
  20. {
  21.     int result = dp1->year - dp2->year;
  22.     if (result == 0)
  23.         result = dp1->month - dp2->month;
  24.     if (result == 0)
  25.         result = dp1->day - dp2->day;
  26.     return result;
  27. }
  28.  
  29.